package com.chihb.controller;

import com.chihb.domain.User;
import com.chihb.service.UserService;
import com.chihb.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import static com.chihb.util.LoginEnum.LOGIN_SUCCESS;
import static com.chihb.util.LoginEnum.REGISTER_SUCCESS;

/**
 * @author chihb
 * @create-time 2024/11/29 10:45
 * @description
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping("/login")
    public Result login(@RequestBody User user) {
        return userService.login(user);
    }

    @RequestMapping("/register")
    public Result register() {
        return new Result(REGISTER_SUCCESS.getCode(), REGISTER_SUCCESS.getMsg());
    }

     // 退出登录
    @RequestMapping("/logout")
    public Result logout(){
        return userService.logout();
    }
}
